function changeColor(obj_id,target_id,target_attr){
	if(target_attr == 'border'){
		$("#"+target_id).css(target_attr,"1px solid #"+$("#"+obj_id).val());
	}
	else{
		$("#"+target_id).css(target_attr,$("#"+obj_id).val());	
	}	
}

function createAfcChannelForm(){
	$.facebox.loading();
	$.ajax({
			data: {
				googleID:$('#googleID').val()
            },
            type: "POST",
            url: "/backyard/create_afc_channel_form",
            cache: false,
            success: function(data){
				$.facebox.reveal(data, '');
            	//alert(data);
            }
        });		
}

function createAfsChannelForm(){
	$.facebox.loading();
	$.ajax({
			data: {
				googleID:$('#googleID').val()
            },
            type: "POST",
            url: "/backyard/create_afs_channel_form",
            cache: false,
            success: function(data){
				$.facebox.reveal(data, '');
            	//alert(data);
            }
        });		
}

function createHostChannelForm(){
	$.facebox.loading();
	$.ajax({
            type: "POST",
            url: "/backyard/create_host_channel_form",
            cache: false,
            success: function(data){
				$.facebox.reveal(data, '');
            	//alert(data);
            }
        });		
}


function createAfcChannel(){
	$.ajax({
			beforeSend: function(){
            	$("#create_loading").show();
        	},
			data: {
				googleID:$('#googleIDForCreateChannel').val(),
				name:$('#newAfcChannelName').val()
            },
            type: "POST",
            url: "/backyard/create_afc_channel",
            cache: false,
            dataType: "json",
            success: function(data){
            	$.facebox.reveal(data['msg'], '');
            	
            	if(data['status']=='true'){
            		$("#channelName").html(data['allNewChannels']);	
            	}
				
				$("#create_loading").hide();
            }
        });		
}

function createAfsChannel(){
	$.ajax({
			beforeSend: function(){
            	$("#create_loading").show();
        	},
			data: {
				googleID:$('#googleIDForCreateChannel').val(),
				name:$('#newAfsChannelName').val()
            },
            type: "POST",
            url: "/backyard/create_afs_channel",
            cache: false,
            dataType: "json",
            success: function(data){
            	$.facebox.reveal(data['msg'], '');
            	
            	if(data['status']=='true'){
            		$("#channelName").html(data['allNewChannels']);	
            	}
				
				$("#create_loading").hide();
            }
        });		
}

function createHostChannel(){
	$.ajax({
			beforeSend: function(){
            	$("#create_loading").show();
        	},
			data: {
				name:$('#newHostChannelName').val()
            },
            type: "POST",
            url: "/backyard/create_host_channel",
            cache: false,
            dataType: "json",
            success: function(data){
            	$.facebox.reveal(data['msg'], '');
            	
            	if(data['status']=='true'){
            		$("#hostChannelNames").html(data['allNewHostChannels']);	
            	}
				
				$("#create_loading").hide();
            }
        });		
}
function getAdCode(accountID){
	$.ajax({
			beforeSend: function(){
            	$("#loading").show();
        	},
			data: {
				accountID:accountID,
				adUnitID:$('#adUnitId').val(),
				hostCustomChannelID:$('#hostCustomChannelId').val(),
            },
            type: "POST",
            url: "/backyard/get_ad_code",
            cache: false,
            success: function(data){
            	$.facebox.loading();
				$.facebox.reveal(data, '');
            	//alert(data);
            	$("#loading").hide();
            }
        });	
}

function getAdCode_show(accountID,adunitID,channelKey){
	$.ajax({
		beforeSend: function(){
			$.facebox.loading();
		},
		data: {
				accountID:accountID,
				adUnitID:adunitID,
				hostCustomChannelID:$('#'+'hostCustomChannelId_'+channelKey).val(),
            },
            type: "POST",
            url: "/backyard/get_ad_code",
            cache: false,
            success: function(data){
            	$.facebox.loading();
				$.facebox.reveal(data, '');
            	//alert(data);
            	$("#loading").hide();
            }
        });	
}

function getAdCodeForm(accountID){
	$.ajax({
			beforeSend: function(){
            	$("#loading").show();
        	},
			data: {
				accountID:accountID
            },
            type: "POST",
            url: "/backyard/get_ad_code_form",
            cache: false,
            success: function(data){
            	$.facebox.loading();
				$.facebox.reveal(data, '');
            	//alert(data);
            	$("#loading").hide();
            }
        });	
}

function newCustomChannelForm(){
	$.facebox.loading();
	$.ajax({
			
			data: {},
            type: "POST",
            url: "/backyard/new_custom_channel_form",
            cache: false,
            success: function(data){
				$.facebox.reveal(data, '');
            }
        });	
}

function newCustomChannel(){
	$.ajax({
			beforeSend: function(){
            	$("#new_channel_loading").show();
        	},
			data: {
				newCustomChannel:$('#newCustomChannel').val()
            },
            type: "POST",
            url: "/backyard/add_custom_channel_to_host",
            cache: false,
            success: function(data){
            	$.facebox.loading();
				$.facebox.reveal(data, '');
            	//alert(data);
            	$("#new_channel_loading").hide();
            }
        });	
}

function saveAdStyle(){
	$.ajax({
			beforeSend: function(){
            	$("#loading").show();
        	},
			data: {
				accountID:$('#accountID').val(),
				adUnitType:$('#adUnitType').val(),
				layout:$('#layout').val(),
                cornerStyles: $('#cornerStyles').val(),
                name: $('#name').val(),
                backgroundColor: $('#backgroundColor').val(),
                borderColor: $('#borderColor').val(),
                textColor: $('#textColor').val(),
                titleColor: $('#titleColor').val(),
                urlColor: $('#urlColor').val()
            },
            type: "POST",
            url: "/backyard/save_ad_style",
            cache: false,
            success: function(data){
            	$.facebox.loading();
				$.facebox.reveal(data, '');
            	//alert(data);
            	$("#loading").hide();
            }
        });		
}

function saveAdStyle_deprecated(getCode){
	$.ajax({
			beforeSend: function(){
            	$("#loading").show();
        	},
			data: {
				getCode:getCode,
				googleID:$('#googleID').val(),
				adUnitType:$('#adUnitType').val(),
				layout:$('#layout').val(),
				isFramedPage:$('#isFramedPage').val(),
                AFCName: $('#AFCName').val(),
                cornerStyles: $('#cornerStyles').val(),
                alternate: $('#alternate').val(),
                channelName: $('#channelName').val(),
                hostChannelNames: $('#hostChannelNames').val(),
                name: $('#name').val(),
                backgroundColor: $('#backgroundColor').val(),
                borderColor: $('#borderColor').val(),
                textColor: $('#textColor').val(),
                titleColor: $('#titleColor').val(),
                urlColor: $('#urlColor').val()
            },
            type: "POST",
            url: "/backyard/save_ad_style",
            cache: false,
            success: function(data){
            	$.facebox.loading();
				$.facebox.reveal(data, '');
            	//alert(data);
            	$("#loading").hide();
            }
        });		
}

function saveSearchBoxStyle(getCode){
	$.ajax({
			beforeSend: function(){
            	$("#loading").show();
        	},
			data: {
				getCode:getCode,
				AFSName: $('#AFSName').val(),
				googleID:$('#googleID').val(),
				country:$('#country').val(),
				locale:$('#locale').val(),
                encoding:$('#encoding').val(),
                searchType:$('#searchType').val(),
                domains:$('#domains').val(),
                backgroundColor: $('#backgroundColor').val(),
                selectedDomain:"",
                isButtonBelow: $('#isButtonBelow').val(),
                isLogoAbove: $('#isLogoAbove').val(),
                isCustomStyle: false,
                logoType: $('#logoType').val(),
                searchStyleName: $('#searchStyleName').val(),
                textBoxLength: $('#textBoxLength').val(),
                textColor: $('#textColor').val(),
                showResultsInNewWindow: $('#showResultsInNewWindow').val(),
                channelName: $('#channelName').val()
            },
            type: "POST",
            url: "/backyard/save_search_box_style",
            cache: false,
            success: function(data){
            	$.facebox.loading();
				$.facebox.reveal(data, '');
            	//alert(data);
            	$("#loading").hide();
            }
        });		
}

function getAFCCode(googleID,AFCName){
	$.ajax({
			beforeSend: function(){
            	$("#loading").show();
        	},
			data: {
				googleID:googleID,
                AFCName: AFCName
            },
            type: "POST",
            url: "/backyard/get_afc_code",
            cache: false,
            success: function(data){
            	$.facebox.loading();
				$.facebox.reveal(data, '');
            	//alert(data);
            	$("#loading").hide();
            }
	});		
}

function getAFSCode(googleID,AFSName){
	$.ajax({
			beforeSend: function(){
            	$("#loading").show();
        	},
			data: {
				googleID:googleID,
                AFSName: AFSName
            },
            type: "POST",
            url: "/backyard/get_afs_code",
            cache: false,
            success: function(data){
            	$.facebox.loading();
				$.facebox.reveal(data, '');
            	//alert(data);
            	$("#loading").hide();
            }
	});		
}
